#
# @lc app=leetcode.cn id=9 lang=python3
#
# [9] 回文数
#
# https://leetcode-cn.com/problems/palindrome-number/description/
#
# algorithms
# Easy (58.40%)
# Likes:    1158
# Dislikes: 0
# Total Accepted:    399.9K
# Total Submissions: 684.7K
# Testcase Example:  '121'
#
# 判断一个整数是否是回文数。回文数是指正序（从左向右）和倒序（从右向左）读都是一样的整数。
#
# 示例 1:
#
# 输入: 121
# 输出: true
#
#
# 示例 2:
#
# 输入: -121
# 输出: false
# 解释: 从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数。
#
#
# 示例 3:
#
# 输入: 10
# 输出: false
# 解释: 从右向左读, 为 01 。因此它不是一个回文数。
#
#
# 进阶:
#
# 你能不将整数转为字符串来解决这个问题吗？
#
#

# @lc code=start

# 92 ms
class Solution:
    def isPalindrome(self, x: int) -> bool:
        if x < 0:
            return False
        if x == 0:
            return True

        original = str(x)
        length = len(original)
        revert = ""

        for i in range(1, length + 1):
            revert = revert + original[length-i]

        return original == revert


# @lc code=end

# 143 ms
# class Solution:
#     def isPalindrome(self, x: int) -> bool:
#         if x < 0:
#             return False
#         if x == 0:
#             return True

#         maxIndex = 0
#         temp = x

#         while temp > 0:
#             temp = temp // 10
#             maxIndex = maxIndex + 1

#         if maxIndex == 1:
#             return True

#         loopMax = maxIndex // 2

#         minTemp = x
#         maxTemp = x

#         for i in range(0, loopMax):
#             maxIndex = maxIndex - 1
#             if (minTemp % 10) != (maxTemp // (10 ** maxIndex)):
#                 return False
#             minTemp = minTemp // 10
#             maxTemp = maxTemp % (10 ** maxIndex)

#         return True

# 100 ms
# class Solution:
#     def isPalindrome(self, x: int) -> bool:
#         if x < 0:
#             return False
#         if x == 0:
#             return True

#         result = 0
#         temp = x

#         while temp > 0:
#             result = result * 10 + temp % 10
#             temp = temp // 10

#         return result == x


solution = Solution()
print(solution.isPalindrome(100))
